Repository navigation
Combine the values of a block with sub-group reductions - #205
Merged
Merged
Conversation
maleadt
force-pushed
the
tb/reduce-subgroups
branch
from
November 5, 2026 11:19
bf0adf3 to
b95020a
Compare
maleadt
force-pushed
the
tb/reduce-subgroups
branch
from
November 5, 2026 12:04
b95020a to
653ccd5
Compare
The reduction kernels combined a block's values in local memory, one per thread, with a tree of log2(block size) synchronized steps. Where the backend has linear sub-groups that can shuffle the accumulator, reduce each sub-group's values with `KI.sub_group_reduce` and then the sub-groups' values, as CUB's `BLOCK_REDUCE_WARP_REDUCTIONS`, keeping one value per sub-group in local memory. This serves the whole-array, by-block, multigroup and second-pass kernels, and the ordered kernel, as the sub-group reductions combine in lane order; `ByLanes` reductions whose lanes fit a sub-group use no local memory at all. The strided kernels, whose lanes span several sub-groups, keep their trees. The tuning's new `subgroups` turns this off, as for the scans on CPU devices. On an RTX 5080 the kernel times are unchanged within noise (Float32 to ComplexF64 sums and maxima, reductions along `dims` of several shapes, in element order, and of structs of 8 to 136 bytes), so this mainly frees local memory.
maleadt
force-pushed
the
tb/reduce-subgroups
branch
from
November 6, 2026 09:59
653ccd5 to
a0f8018
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The reduction kernels combine a block's values in local memory, one per thread, with a tree of log2(block size) synchronized steps. Where the backend has linear sub-groups that can shuffle the accumulator, they now reduce each sub-group's values with
KI.sub_group_reduce, and then the sub-groups' values, as CUB'sBLOCK_REDUCE_WARP_REDUCTIONS. A block keeps one value per sub-group in local memory instead of one per thread.block_reduce, which also replaces the block scan of the ordered kernel, as the sub-group reductions combine in lane order.ByLanes: lanes that fit a sub-group reduce withsub_group_reduce(op, x, lanes)and no local memory.subgroupsturns this off, as for the scans;cpu_reduce_tuningdoes, since CPUs run sub-group operations as block barriers. A test forces it on for the host backend, so that PoCL runs the sub-group paths in CI.Kernel times on an RTX 5080, interleaving
subgroups=falseandtrue(median of 6 runs, each the best of 100), are unchanged within noise:sumFloat32, 10^8sumFloat64, 10^7maxFloat32, 10^8sumFloat32 4096²,dims=1sumFloat32 256×10^5,dims=1sumFloat32 10^6×8,dims=1sumFloat32 4096²,dims=2sumFloat32, 10^7sumof 136-byte structs, 10^6sumof 136-byte structs 512×2000,dims=1Structs of 8 to 64 bytes over 15 runs and ComplexF64 sums are within 1%. So this mostly frees local memory, which matters for wide accumulators; it doesn't speed up the memory-bound reductions measured here.